local conf = require("ufe.config")
require("ufe.ufe_module")
local u = require("ufe.util.update")
local ox = require("posix_c")

ngx.log(ngx.DEBUG, "UFE init in init_by_lua")
local path = conf.ufe_path
assert(path, "must set ufe_path in ufe config")
path = path .. "policies/"
local entries = ox.dir(path)
assert(entries, "read "..path.." failed")

for _, fn in ipairs(entries) do
    local fstat, m = ox.stat(path..fn)
    if fstat and fstat.type == "regular" and string.match(fn, "%.lua$") then
         require("ufe.policies." .. string.sub(fn, 1, -5))
    else
         ngx.log(ngx.INFO, "cannot read file:",path.."/"..fn)
    end
end
shared_conf = ngx.shared.ufe_shared_dict
ufe_lock = ngx.shared.ufe_lock
assert(shared_conf, "cannot get shared memory for conf")
assert(ufe_lock, "cannot get shared memroy for lock")

assert(u.check_config())


